package com.ymatou.iapi.shoppingcartservice.service;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.google.gson.GsonBuilder;
import com.ymatou.iapi.shoppingcartservice.parameter.ShoppingcartProductBean;
import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.YMTDateUtil;

public class AddShoppingCartCall extends YmatouAutoTestCall {
private static String opurl="/api/shoppingcart/add";
	
	public AddShoppingCartCall(){
		super(EnvSetup.getSystemUrl("shoppingcartservice"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader(){
		client.addHeader("Content-Type", "application/json");
	}
	
	//get bean by file
	public static ShoppingcartProductBean getAddShoppingCartRequestFromFile(String fileName, Map<String, Object> updateMap){
		if (fileName == null || fileName.equals("")){
			fileName = "addshoppingcartcalltpl.json";
		}
			
		if (updateMap == null){
			updateMap = new HashMap<>();
		}
			
		String fullPath = "com.ymatou.iapi.shoppingcartservice/AddProductCall/" + fileName + ".json";
			
		JSONObject jsonBean = JsonBeanHelper.getJsonBean(fullPath);
			
		/*if (!updateMap.keySet().contains("product->productName")){
			updateMap.put("product->productName","自动化测试_"+ YMTDateUtil.getSysTime("yyyy-MM-dd-HH-mm-ss-SSS"));
		}*/
			
		JsonBeanHelper.updateJsonBean(jsonBean, updateMap);
			
		String jsonStr = jsonBean.toString();
		return new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create().fromJson(jsonStr, ShoppingcartProductBean.class);
	}
}
